package edu.visualization.homework.entity;

import java.io.File;

public class Constructor {
	
	/**
	 * 获得一个二叉树
	 * 
	 * @return
	 */
	public static TreeNode getTheBinaryTree(){
		
		TreeNode root = new TreeNode("/", null);
		TreeNode left = new TreeNode("*",root);
		TreeNode right = new TreeNode("-",root);
		
		root.addChild(right);
		root.addChild(left);

		//right 
		right.addChild(new TreeNode("1",right));
		right.addChild(new TreeNode("R",right));
		//left
		left.addChild(new TreeNode("A",left));
		
		TreeNode leftright = new TreeNode("-",left);
		left.addChild(leftright);
		
		leftright.addChild(new TreeNode("1",leftright));
		
		TreeNode leftrightright = new TreeNode("^", leftright);
		leftright.addChild(leftrightright);
		
		leftrightright.addChild(new TreeNode("R",leftrightright));
		leftrightright.addChild(new TreeNode("n",leftrightright));
		
		return root;
	}
	
	public static TreeNode getTheTree(File file){
		
		TreeNode root = new TreeNode(file.getName(), null);
		if(file.isDirectory()){
			for(File childFile:file.listFiles()){
				TreeNode child = getTheTree(childFile);
				child.setParent(root);
				root.addChild(child);
			}
		}
		return root;
	}
	
}
